import { Dept } from '../api/Dept';
import { Room } from '../api/Room';
import { events } from '../utils/events';

export namespace DeptRegistry {
	const depts = new Map<string, new (id: string) => Dept>();

	export function registry(id: string, dept: new (id: string) => Dept) {
		depts.set(id, dept);
	}

	export function get(id: string) {
		const dept = depts.get(id);
		if (!dept) return;
		return new dept(id);
	}

	events.on('roomInit', (room: Room) => {
		depts.forEach((dept, key) => {
			room.addDept(new dept(key));
		});
	});
}
